// const baseURL = 'https://www.forerunnercollege.com/soApi';
const baseURL = 'http://127.0.0.1:8082';

export default function(url:string,data={},method:"POST" | "GET" = "POST") {
	
	return new Promise((reslove,reject) => {
		
		const token = uni.getStorageSync("token");
		
		uni.request({
			url: `${baseURL}${url}`,
			data,
			method,
			header: {
				// 异步请求，如果是json，自己需要加上Content-Type
				'Content-Type': 'application/json',
				'Authorization': token
				
			},
			success(res:any) {
				if (res.data.status < 0) {
					uni.showToast({
						title: res.data.msg,
						icon: "error",
					});
				}
				reslove(res);
			},
			fail(error) {
				uni.showToast({
					title: "网络错误",
					icon: "error",
				});
				reject(error);
			}
		})
	})
	
}